<template>
  <div id="data-box">
    <div class="data-div1">
      <el-table
          :data="tableData"
          style="width: 100%"
          :row-class-name="tableRowClassName">
        <el-table-column
            show-overflow-tooltip
            prop="city1"
            label="城市">
        </el-table-column>
        <el-table-column
            show-overflow-tooltip
            prop="scenicSpot"
            label="景点名称">
        </el-table-column>
        <el-table-column
            show-overflow-tooltip
            prop="remarkDate"
            label="点评时间">
        </el-table-column>
        <el-table-column
            show-overflow-tooltip
            prop="remarkIp"
            label="点评ip地址">
        </el-table-column>
        <el-table-column
            show-overflow-tooltip
            prop="userNik"
            label="用户呢称">
        </el-table-column>
        <el-table-column
            show-overflow-tooltip
            prop="starLevel"
            label="点评星级">
        </el-table-column>
        <el-table-column
            show-overflow-tooltip
            prop="reviewC"
            label="点评内容">
        </el-table-column>
      </el-table>
    </div>
    <div class="data-div2" v-show="tableData.length > 0">
      <el-pagination
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="currentPage1"
          :page-sizes="[16, 32, 64, 128]"
          :page-size="100"
          layout="total, sizes, prev, pager, next, jumper"
          :total=pageCount>
      </el-pagination>
    </div>
  </div>
</template>

<script>
export default {
  name: 'DataManagement',
  data() {
    return {
      pageSize: 16,
      pageCount: 0,
      currentPage1: 1,
      tableData: []
    }
  },
  mounted() {
    this.getPageCount();
    this.getDataAll(0, this.pageSize);
  },
  methods: {
    tableRowClassName({row, rowIndex}) {
      if (rowIndex === 1) {
        return 'warning-row' + row;
      } else if (rowIndex === 3) {
        return 'success-row';
      }
      return '';
    },
    //  分页
    handleSizeChange(val) {
      this.pageSize = val;   // 没有分页数
    },
    handleCurrentChange(val) {
      this.tableData = [];
      let start = (val - 1) * this.pageSize;
      this.getDataAll(start, this.pageSize)

    },
    getPageCount() {
      this.$axios.get('/api/vis/data11', {}).then(res => {
        if (res.data.code === 20041) {
          this.pageCount = res.data.data;
        }
      }).catch(error => {
        this.open4(error);
      })
    },
    getDataAll(start, end) {
      this.$axios.post('/api/vis/data12', {
          "start": start,
          "end": end
      }).then(res => {
        if (res.data.code === 20041) {
          this.tableData = [];
          for (let i = 0; i < res.data.data.length; i++) {
            this.tableData.push(
                {
                  city1: res.data.data[i].param1,
                  scenicSpot: res.data.data[i].param2,
                  remarkDate: res.data.data[i].param3,
                  remarkIp: res.data.data[i].param4,
                  userNik: res.data.data[i].param5,
                  starLevel: res.data.data[i].param6,
                  reviewC: res.data.data[i].param7,
                }
            )
          }
        }
      }).catch(error => {
        this.open4(error);
      })
    }
  }
}
</script>

<style scoped>

  #data-box {
    height: 100%;
    width: 100%;
    .el-table .warning-row {
      background: oldlace;
    }

    .el-table .success-row {
      background: #f0f9eb;
    }
    overflow-x: hidden;
    overflow-y: auto;
  }
  #data-box .data-div1 {
    width: 100%;
    margin: auto;
  }
  #data-box .data-div2 {
    width: 40%;
    margin: auto;
  }

</style>